#define _CRT_SECURE_NO_WARNINGS 1
#include<stdlib.h>
#include<stdbool.h>
int cmp(const void* a, const void* b)
{
    return *(int*)a - *(int*)b;
}


bool* checkArithmeticSubarrays(int* nums, int numsSize, int* l, int lSize, int* r, int rSize, int* returnSize) {
    *returnSize = lSize;
    bool* ans = (bool*)calloc(lSize, sizeof(bool));
    int *tmp = (int*)calloc(numsSize, sizeof(int));
    memset(tmp, 0, sizeof(tmp));
    for (int i = 0; i < lSize; ++i)
    {
        memmove(tmp, nums + l[i], (r[i] - l[i] + 1) * sizeof(int));
        qsort(tmp, r[i] - l[i] + 1, sizeof(int), cmp);
        if ((tmp[r[i] - l[i]] - tmp[0]) % (r[i] - l[i]) != 0)
            continue;
        if (r[i] - l[i] <= 1)
            ans[i] = true;
        else
        {
            int sub = tmp[1] - tmp[0];
            int j = 2;
            for (j = 2; j < r[i] - l[i] + 1; ++j)
            {
                if (tmp[j] - tmp[i] != sub)
                    break;
            }
            if (j == r[i] - l[i] + 1)
                ans[i] = true;
        }
    }
    return ans;
}

int main()
{
    int nums[] = { 4,6,5,9,3,7 };
    int l[] = { 0,0,2 };
    int r[] = { 2,3,5 };
    int num = 0;
    bool* ans = checkArithmeticSubarrays(nums, 6, l, 3, r, 3, &num);
    return 0;
}